import java.io.File;
import java.util.List;
import java.util.Random;

public class FeelingLuckyLauncher {

	private void getRandomRom(String path) {
		File[] files = new File(path).listFiles();
		int random = new Random().nextInt(files.length);
		System.out.print("\"" + path + "\\" + files[random].getName() + "\"");
	}
	
	private void getRomInfo(String path, String rom) {
		HistoryDatManager historyManager = new HistoryDatManager(path);
		List<String> result = historyManager.getRomInfo(rom);
		for (String line : result) {
			System.out.println(line);
		}	
	}
	
	/**
	 * Usage -
	 * To fetch random rom:
	 *		java FeelingLuckyLauncher <path to rom dir>
	 * To fetching rom info from history.dat:
	 *		java FeelingLuckyLauncher <path to history.dat> <rom> 
	 */
	public static void main(String[] args) {
		FeelingLuckyLauncher launcher = new FeelingLuckyLauncher();
		if (args.length == 2) {
			launcher.getRomInfo(args[0], args[1]);
		} else {
			launcher.getRandomRom(args[0]);
		}		
	}
}
